package com.googlecode.continuity.core.server.mvc.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import com.googlecode.continuity.core.server.mvc.ContinuityModel;

/**
 * ErrorController serves an error view, providing the error code.
 *
 * todo: replace with generic controller?
 *
 * @author Peter Schmitt <aragos@aragos.de>
 */
public class ErrorController implements Controller {
  /**
   * Logger for this class and subclasses
   */
  protected final Log logger = LogFactory.getLog(getClass());

  public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    String error = request.getParameter("error");
    //  TODO: no literals as titel! use templates/messages/i18n instead
    ContinuityModel model = new ContinuityModel();
    model.put("error", error);

    logger.info("Returning error view with error code: " + error);
    return new ModelAndView("error", model);
  }
}
